package com.zb.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.ha.DataSourceCreator;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;

import javax.sql.DataSource;

/**
 * @Author: 张波
 * @Time: 2025/8/21 19:03
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
public class DataSourceConfig {
	@Value("${jdbc.driver}")
	private String DriverName;
	@Value("${jdbc.url}")
	private String Url;
	@Value("${jdbc.username}")
	private String userName;
	@Value("${jdbc.password}")
	private String password;
	@Value("${initialSize}")
	private int initialSize;
	@Value("${minIdle}")
	private int minIdle;
	@Value("${maxActive}")
	private int maxActive;
	@Bean("DataSource")
	public DataSource getMyConnection(){
		DruidDataSource druidDataSource = new DruidDataSource();
		druidDataSource.setDriverClassName(DriverName);
		druidDataSource.setUrl(Url);
		druidDataSource.setUsername(userName);
		druidDataSource.setPassword(password);
		druidDataSource.setInitialSize(initialSize);
		druidDataSource.setMinIdle(minIdle);
		druidDataSource.setMaxActive(maxActive);
		return druidDataSource;
	}
}
